# L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

# def by_name(t):
#     pass

# L2 = sorted(L, key=by_name)
# print(L2)

# def add(x, y, f):
#     return f(x) + f(y)

# print(add(-5, 6, abs))

# def f(x):
#     return x * x
# r = map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9])
# print(list(r))

# L = []
# for n in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
#     L.append(f(n))
# print(L)

# num = [1, 2, 3, 4, 5]
# squared = map(lambda x: x * x, num)
# print(list(squared))


# from functools import reduce
# def add(x, y):
#     return x + y

# print(reduce(add, [1, 3, 5, 7, 9]))

# print(sum([1, 2, 3, 4, 5]))

# def normalize(name):
#     return name[0].upper() + name[1:].lower()

# # 测试:
# L1 = ['adam', 'LISA', 'barT']
# L2 = list(map(normalize, L1))
# print(L2)

# from functools import reduce

# def prod(L):
#     return reduce

# print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9]))
# if prod([3, 5, 7, 9]) == 945:
#     print('测试成功!')
# else:
#     print('测试失败!')


# L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

# def by_name(t):
#     return t[0]

# L2 = sorted(L, key=by_name)
# print(L2)

# L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]
L = [ {'name':'Bob', 'score': 75}, {'name':'Adam', 'score': 92}, {'name':'Bart', 'score': 66}, {'name':'Lisa', 'score': 88}]

def by_score(t):
    return t['name']

L2 = sorted(L, key=by_score)
print(L2)
